<!-- 费用报销 -->
<template>
	<view>
		<u-form :model="model" :rules="rules" ref="form" labelPosition="top" labelWidth="auto" :labelStyle="{
				fontSize: '14px',
				color: '#B2B2B2',
				lineHight: '20px'
			}">
		  <view class="basic-style">
		    <view class="basic-title basic-border">费用类别</view>
		    <view class="py-1 space-y-1" style="width: 100%">
					<u-form-item label="费用类别" props="feeCategory" required>
			  <h-radio-group style="padding: 12upx 0;" v-model="model.feeCategory" dictName="fee_category" @change='feeCategoryChange'/>
			</u-form-item>
			<text v-text="model.feeCategory=='0'?'职工薪酬类报销（不含集中采购的节日福利）':model.feeCategory=='1'?'需签订合同的采购类报销':'其他场景'"/>
		    </view>
		</view>
		<!-- 基本信息模块 -->
		<view class="basic-style">
		    <view class="basic-title basic-border">基本信息</view>
		    <u-form-item label="单据编号" prop="billNo" required>
		        <u--input v-model="model.billNo" disabled/>
		    </u-form-item>

		    <u-form-item label="报销人" prop="proposer" required>
		        <h-select-person-input
		          style="width: 100%"
		          disabled
		          v-model="model.proposer"
		          placeholder="请选择报销人"
		          border="surround"
		          suffixIcon="arrow-down-fill"
		          :suffixIconStyle="{ color: '#B2B2B2' }"
		          objectField="model.proposer"/>
		    </u-form-item>
		      <u-form-item label="所在部门" prop="proposerDeptId" required>
		        <h-select-depart-input
		          disabled
		          v-model="model.proposerDeptId"
		          :departName="model.proposerDeptText"
		          placeholder="请选择部门"
		          border="surround"
		          style="width: 100%"
		          suffixIcon="arrow-down-fill"
		          :suffixIconStyle="{ color: '#B2B2B2' }"
		          :title.sync="model.proposerDeptText"/>
		      </u-form-item>
					<u-form-item label="填表时间" prop="createTime" required>
		        <u--input v-model="model.createTime" placeholder="请选择填表时间" disabled/>
		    </u-form-item>
					<u-form-item label="费用所属团队" prop="teamId" required>
		        <h-select-team-input
						  isApi="expenseReimbursement"
							:proposerDeptId="model.proposerDeptId"
		          style="width: 100%"
		          v-model="model.teamId"
		          objectField="model.teamId"
		          placeholder="请选择费用所属团队"
		          border="surround"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
		          :tdlx="3"
		          @input="handleTeamChange"/>
		    </u-form-item>
		    <u-form-item label="申请公司" prop="applicant" required>
					<h-select-company-input
						style="width: 100%"
						v-model="model.applicant"
						border="surround"
						placeholder="请选择申请公司"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						objectField="model.applicant"
						@input="companyChange"/>
		    </u-form-item>
		    <u-form-item label="团队费用类别" prop="teamFeeCategory" required>
		        <h-select-input-tag
		          class="w-100"
		          v-model="model.teamFeeCategory"
		          placeholder="请选择团队费用类别"
		          border="surround"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
		          dictName="team_fee_category"/>
		    </u-form-item>

			<u-form-item label="费用所属年度" prop="teamYear" v-if="model.teamYear=='2023'">
				<h-select-input-tag
					disabled
				  class="w-100"
				  v-model="model.teamYear"
				  placeholder="请选择费用所属年度"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{ color: '#B2B2B2' }"
				  border="surround"
				  dictName="tdnd_type"/>
			</u-form-item>
			<u-form-item label="单据类型" prop="billCategory" required>
			    <h-select-input-tag
			      class="w-100"
			      v-model="model.billCategory"
			      placeholder="请选择单据类型"
			      border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
			      dictName="bill_category"/>
			</u-form-item>
			<u-form-item label="本次是否付款" prop="isPay" required>
			    <h-select-input-tag
			      class="w-100"
			      v-model="model.isPay"
			      objectField="model.isPay"
			      placeholder="请选择本次是否付款"
			      border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						@change="isPay"
			      dictName="is_pay"/>
			</u-form-item>
		    <u-form-item label="本次付款金额(元)" prop="payAmount" required>
						<h-money-input :disabled="model.isPay=='0'" placeholder="请输入本次付款金额" v-model="model.payAmount"></h-money-input>
		    </u-form-item>
			<u-form-item label="累计报销金额(元)" prop="accumulateAmount">
			    <!-- <u--input disabled v-model="model.accumulateAmount" placeholder="请输入累计报销金额"/> -->
					<h-money-input disabled placeholder="请输入累计报销金额" v-model="model.accumulateAmount"></h-money-input>
			</u-form-item>
			<u-form-item label="本次累计冲账金额(元)" prop="chargedAmount">
					<h-money-input disabled placeholder="请输入本次累计冲账金额" v-model="model.chargedAmount"></h-money-input>
			</u-form-item>
			<u-form-item label="是否使用商务卡" prop="isUseBusinessCard" required>
				<h-select-input-tag
					class="w-100"
					v-model="model.isUseBusinessCard"
					objectField="model.isUseBusinessCard"
					placeholder="请选择是否使用商务卡"
					border="surround"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{ color: '#B2B2B2' }"
					dictName="YES_OR_NO"/>
			</u-form-item>
			<u-form-item label="报销说明" prop="applyExplain" required>
			  <u--textarea :confirm-type="null" maxlength="500" count v-model="model.applyExplain" placeholder="请输入报销说明"/>
			</u-form-item>
			
			<!-- <u-form-item label="费用类别" props="feeCategory" required>
			  <h-radio-group style="padding: 12upx 0;" v-model="model.feeCategory" dictName="fee_category" @change='feeCategoryChange'/>
			</u-form-item>
			<text v-text="model.feeCategory=='0'?'职工薪酬类报销（不含集中采购的节日福利）':model.feeCategory=='1'?'需签订合同的采购类报销':'其他场景'"/> -->
			
		</view>
		<!-- 费用报销信息 -->
		<view class="basic-style">
			<view class="basic-title basic-border">费用报销信息</view>
			<!-- 工资福利类 -->
			
			<salaryModel ref='salaryRef' @inputAmount="inputAmount" :feeCategory='model.feeCategory'/>
			<!-- 采购类 -->
			<!-- getInformation => 获取账户信息 projectChange => 选择项目 -->
			<purchaseModel ref="purchaseRef" @inputAmount="inputAmount" @getInformation="getInformation" @projectChange="projectChange" :teamId='model.teamId' :companyId='model.applicant' :feeCategory='model.feeCategory'/>
			<!-- 费用类 -->
			<costModel ref='costRef' :isRelProject='model.isRelProject' @getDailyFeeInfoList="getDailyFeeInfoList" @inputAmount="inputAmount" @change="changeCostRef" :teamId='model.teamId' :companyId='model.applicant' :feeCategory='model.feeCategory'/>
		</view>
		<view class="basic-style">
			<u-form-item label="结算方式" prop="settleType" required v-if="model.isPay=='1'">
					<h-dict-select
					
						style="width: 100%" 
						v-model="model.settleType" 
						placeholder="请选择结算方式" 
						dictName="settle_type" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
						@change="radioSettleType"
					></h-dict-select>
			</u-form-item>
			<!-- 转账才需要填写 -->
			<template v-if="model.settleType=='0'">
				<u-form-item label="转账类型" prop="transferType" required v-if="model.isPay=='1'">
						<h-dict-select
							style="width: 100%" 
							v-model="model.transferType" 
							placeholder="请选择转账类型" 
							dictName="transfer_type"
							suffixIcon="arrow-down-fill" 
							:suffixIconStyle="{color: '#B2B2B2'}"
							@change="radioTransferType"
						></h-dict-select>
				</u-form-item>
				<u-form-item label="收款户名" prop="accountName" required v-if="model.transferType">
					<h-select-person-input
					  v-model="model.accountName"
						v-if="model.transferType=='1'"
						objectField="model.accountName"
					  class="w-100"
					  placeholder="请选择收款户名"
					  border="surround"
					  suffixIcon="arrow-down-fill"
					  :suffixIconStyle="{color: '#B2B2B2'}"
					  @input='selectAccountName'/>
					  
					  <h-select-customer-input-popup
							v-if="model.transferType=='2'"
						  :isFinance="true"
					    style="width: 100%"
					    v-model="model.accountName"
					    objectField="model.accountName"
					    commercialType="2"
					    placeholder="请选择关联往来单位"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
							:isJudge='true'
							@onJudge='onJudge'
					    border="surround"/>
					  
						<!-- <h-select-customer-input
							v-if="model.transferType=='2'"
						  style="width: 100%"
						  v-model="model.accountName"
						  objectField="model.accountName"
						  commercialType="2"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
						  placeholder="请选择关联往来单位"
						  border="surround"
							@input="selectCustomer"/> -->
				</u-form-item>
				<template v-if="model.accountName">
					<u-form-item label="收款方开户行" prop="bankName" required>
					    <u--input v-model="model.bankName" disabled placeholder="请输入收款方开户行"/>
					</u-form-item>
					<u-form-item label="开户行联行号" prop="cnapsCode" required>
					    <u--input v-model="model.cnapsCode" disabled placeholder="请输入收款方开户行"/>
					</u-form-item>
					<u-form-item label="收款方银行账户" prop="accountNo" required>
					    <u--input v-model="model.accountNo" disabled placeholder="请输入收款方银行账户" :maxlength="32"/>
					</u-form-item>
					<u-form-item label="打款附言" prop="postscript" required>
							<u--textarea :confirm-type="null" maxlength="200" count v-model="model.postscript" placeholder="请输入打款附言"/>
					</u-form-item>
				</template>
			</template>
			<template v-if="model.isPay">
				<u-form-item label="冲账单据类型" prop="relBillType" :required="model.isPay==0">
					<!-- <h-dict-select
						v-if="model.feeCategory=='2' && model.isRelProject=='1' && this.$refs.costRef.costList.length!=0"
						style="width: 100%" 
						v-model="model.relBillType" 
						placeholder="请选择冲账单据类型" 
						dictName="rel_bill_type" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
						@input="radioChange"
					></h-dict-select>
					<h-dict-select
						v-else
						style="width: 100%" 
						v-model="model.relBillType" 
						placeholder="请选择冲账单据类型" 
						dictName="rel_bill_type_no_project" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
						@input="radioChange"
					></h-dict-select> -->
					<h-select-input-tag
						v-if="model.feeCategory=='2' && model.isRelProject=='1' && this.$refs.costRef.costList.length!=0"
						style="width: 100%" 
						v-model="model.relBillType" 
						isDeselect
						placeholder="请选择冲账单据类型" 
						border="surround" 
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }" 
						dictName="rel_bill_type" 
						@change="radioChange"
					></h-select-input-tag>
					<h-select-input-tag
						v-else
						style="width: 100%" 
						v-model="model.relBillType" 
						isDeselect
						placeholder="请选择冲账单据类型" 
						border="surround" 
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }" 
						dictName="rel_bill_type_no_project" 
						@change="radioChange"
					></h-select-input-tag>
				</u-form-item>
				<u-form-item label="关联单据单号" prop="relBillId" v-if="model.relBillType==3" :required="model.isPay==0">
						<h-select-borrowbill-input-popup
							v-if="model.relBillType=='1'"
							:disabled=" !model.teamId || !model.applicant"
							:teamId="model.teamId"
							:companyId="model.applicant"
							:proposer="userInfo.empId"
							settleAccounts="0"
							checkStatus="2"
							class="w-100"
							v-model="model.relBillId"
							placeholder="请选择借款单单据"
							border="surround"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
							@realChange="handleApplicantChange"/>
						
					<!-- <selectPayPop
						v-if="model.relBillType=='2'"
						:teamId="model.teamId"
						:disabled=" !model.teamId || !model.applicant"
						:applicant="model.applicant"
						class="w-100"
						v-model="model.relBillId"
						placeholder="请选择付款单单据"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						@realChange="handleApplicantChange"/> -->
					<h-select-finance-deposit-bill-input
						v-if="model.relBillType=='3'"
						:disabled="!model.teamId || !model.applicant || this.$refs.costRef.costList.length==0"
						v-model="model.relBillId"
						:teamId="model.teamId"
						:projectId="this.$refs.costRef.costList&&this.$refs.costRef.costList.length?this.$refs.costRef.costList[0].projectId:''" 
						:applicant="model.applicant"
						objectField="model.relBillId"
						style="width: 100%;"
						placeholder="请选择保证金单据"
						@input="handleApplicantChange"
					>
					</h-select-finance-deposit-bill-input>
				</u-form-item>
				<!-- 借款单 -->
				<!-- <template v-if="model.relBillType=='1'">
					<u-form-item label="借款金额(元)" prop="borrowLoanAmount">
							<u--input disabled v-model="model.borrowLoanAmount" placeholder="请输入借款金额"/>
					</u-form-item>
					<u-form-item label="已还金额(元)" prop="borrowOnloanAmount">
							<u--input disabled v-model="model.borrowOnloanAmount" placeholder="请输入已还金额"/>
					</u-form-item>
					<u-form-item label="未还金额(元)" prop="borrowUnloanAmount">
							<u--input disabled v-model="model.borrowUnloanAmount" placeholder="请输入未还金额"/>
					</u-form-item>
					<u-form-item label="剩余未付金额(元)" prop="borrowPayAmount">
							<u--input disabled v-model="model.borrowPayAmount" placeholder="请输入剩余未付金额"/>
					</u-form-item>
				</template> -->
				<!-- 付款单（预付款） -->
				<!-- <template v-if="model.relBillType=='2'">
					<u-form-item label="预付金额(元)" prop="payPayableAmount">
							<u--input disabled v-model="model.payPayableAmount" placeholder="请输入预付金额"/>
					</u-form-item>
					<u-form-item label="已冲账金额(元)" prop="payOnChargedAmount">
							<u--input disabled v-model="model.payOnChargedAmount" placeholder="请输入已冲账金额"/>
					</u-form-item>
					<u-form-item label="未冲账金额(元)" prop="payUnChargedAmount">
							<u--input disabled v-model="model.payUnChargedAmount" placeholder="请输入未冲账金额"/>
					</u-form-item>
				</template> -->
				<view v-if="model.relBillType==1||model.relBillType==2">
					<view class="space-y-1 py-1">
						<u-button size="small" type="primary" @click="addReverse">新增</u-button>
					</view>
					<view class="trip-form-data">
						<u-collapse ref="collapseView3">
							<u-collapse-item :title="`${model.relBillType==1?'借款单单据':'付款单单据'}${index + 1}`" v-for="(item, index) in model.chargedInfoList"
								:key="index">
								<ReversePaymentFormInfo :relBillType="model.relBillType" :item="item" :index="index" @edit="handleEditReverseForm"
									@remove="handleRemoveReverseForm" />
							</u-collapse-item>
						</u-collapse>
					</view>
					<u-popup :round="10" mode="bottom" :closeOnClickOverlay="false" :show="showReverseModal"
						@close="closeReverseModal" @open="openReverseModal">
						<ReversePaymentForm :childSource="model.chargedInfoList" :teamId="model.teamId" :relBillType="model.relBillType" :applicant="model.applicant" ref="ReverseForm" :index="index" @submit="handleReverseSubmit" @close="closeReverseModal" />
					</u-popup>
				</view>
				<template v-if="model.relBillType=='3'">
					<u-form-item label="保证金总额(元)" prop="depositRemittanceAmount">
							<u--input disabled v-model="model.depositRemittanceAmount" placeholder="请输入保证金总额"/>
					</u-form-item>
					<u-form-item label="服务费(元)" prop="depositServiceCharge">
							<u--input disabled v-model="model.depositServiceCharge" placeholder="请输入服务费"/>
					</u-form-item>
					<u-form-item label="利息金额(元)" prop="depositInterestAmount">
							<u--input disabled v-model="model.depositInterestAmount" placeholder="请输入利息金额"/>
					</u-form-item>
					<u-form-item label="归还金额(元)" prop="depositReturnAmount">
							<u--input disabled v-model="model.depositReturnAmount" placeholder="请输入归还金额"/>
					</u-form-item>
					<u-form-item label="未归还金额(元)" prop="depositUnreturnAmount">
							<u--input disabled v-model="model.depositUnreturnAmount" placeholder="请输入未归还金额"/>
					</u-form-item>
				</template>
			</template>
		</view>
		<!-- 附件信息 -->
		<view class="basic-style">
		    <view class="basic-title basic-border">附件信息</view>
		    <view class="py-1 space-y-1" style="width: 100%">
		      <view style="color: red">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
		      <h-upload-file v-model="model.attachments" :isIcon="false"/>
		      <file-list v-if="model.attachments" v-model="model.attachments" :isDelete="true"/>
		    </view>
		</view>
		<view class="space-x-1 px-1 btn_position">
			<u-button :disabled="isSubmit" type="primary" :plain="true" text="保存" @click="getSubmitRequest(0)"></u-button>
			<u-button :disabled="isSubmit"  type="primary"  text="保存并提交" @click="getSubmitRequest(1)"></u-button>
		</view>
		<view style="height: 100rpx"></view>
	</u-form>
	
	<u-toast ref="uToast"></u-toast>
	<ProcessNodeConfiguration ref="processConfig" @ok="onOk"/>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	import moment from 'moment'
	import {reimburseSlipBillNo,feeReimburseAdd,feeReimburseEdit} from '@/api/finance/ErpFinanceRepaymentSlipForm'
	import fileList from '@/pages/synergy/components/fileList.vue'
	import salaryModel from './reimComp/salaryModel.vue'
	import purchaseModel from './reimComp/purchaseModel.vue'
	import costModel from './reimComp/costModel.vue'
	import selectListTag from './reimComp/comp/select-list-tag.vue'
	import selectPayPop from './reimComp/comp/h-select-pay-input-popup.vue'
	import ProcessNodeConfiguration from '@/components/ProcessNodeConfiguration/ProcessNodeConfiguration.vue'
	import http from '@/utils/request'
	import { queryByIdreimbursementBill } from '@/api/index.js'
	import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'
	import ReversePaymentForm from './components/ReversePaymentForm.vue'
	import ReversePaymentFormInfo from './components/ReversePaymentFormInfo.vue'
	export default {
		components: {
			fileList,salaryModel,purchaseModel,costModel,selectListTag,selectPayPop,ProcessNodeConfiguration,
			ReversePaymentForm,ReversePaymentFormInfo
		},
		computed: {
		  ...mapState(['userInfo']),
		},
		provide() {
			return {
				dictOptions: this.dictOptions,
			}
		},
		data() {
			return {
				dailyFeeInfoList: [], // 费用类列表数据
				isSubmit: false,
				filterMultiDictText,
				initDictOptions,
				dictOptions: {},
				showReverseModal: false,
				index: null,
				basicForm: {},
				id:'',
				isReset: false,//是否还原即将修改的数据
				loading: false,
				/* 表单的form字段 */
				model:{
					billNo:'',//单据编号
					proposer: '',//报销人
					proposerDeptId: '',//所在部门
					createTime: '',//填表时间
					applicant: '',//申请公司
					teamFeeCategory:'',//团队费用类别
					teamId:'',//费用所属团队
					teamYear:'',//费用所属年度
					billCategory:'',//单据类型
					isPay:'',//本次是否付款
					payAmount:'',// 本次付款金额（元）
					accumulateAmount:0,// 累计报销金额（元）
					chargedAmount: '', // 本次累计冲账金额
					isUseBusinessCard: '', // 是否使用商务卡
					applyExplain:'',//  报销说明
					feeCategory:'0',// '0':工资福利,'1':采购,'2':费用类,
					settleType:'',//结算方式
					settleType_dictText:'',
					transferType:'',//转账类型
					accountName:'',//收款户名
					bankName:'',//收款方开户行
					cnapsCode:'',//开户行联行号
					accountNo:'',//收款方银行账户
					postscript:'',//打款附言
					relBillType:'',//冲账单据类型
					relBillId: "",//关联单据单号
					borrowPayAmount: "",//剩余未付金额
					borrowOnloanAmount: "",//已还金额
					borrowLoanAmount: "",//借款金额
					borrowUnloanAmount: "",//未还金额
					
					payApplicant: "",
					payPayeeName: "",
					payPayableAmount: "",//预付金额
					payUnChargedAmount: "",//未冲账金额
					payOnChargedAmount: "",//已冲账金额
					payPaidAmount: "",
					payDeductionAmount: "",
					depositRemittanceAmount: "",
					depositReturnAmount: "",
					depositUnreturnAmount: "",
					depositServiceCharge: "",
					depositInterestAmount: "",
					
					isRelProject:'1',
					// 附件
					attachments: null,
					chargedInfoList: [],
				},
				/* 表单验证 */
				rules:{
					billNo: [{ required: true, message: '请输入单据编号!', trigger: 'change' }],
					createTime: [{ required: true, message: '请选择填表时间!', trigger: 'change' }],
					proposer: [{ required: true, message: '请选择报销人!', trigger: 'change' }],
					proposerDeptId: [{ required: true, message: '请选择所在部门!', trigger: 'change' }],
					
					applicant: [{ required: true, message: '请选择申请公司!', trigger: 'change' }],
					teamFeeCategory: [{ required: true, message: '请选择团队费用类别!', trigger: 'change' }],
					teamId: [{ required: true, message: '请选择费用所属团队!', trigger: 'change' }],
					billCategory: [{ required: true, message: '请选择单据类型!', trigger: 'change' }],
					isPay: [{ required: true, message: '请选择本次是否付款!', trigger: 'change' }],
					payAmount: [
						{ required: true, message: '请输入本次付款金额!', trigger: ['change', 'blur'] },
						// {pattern: /^(?!0\.00)(?!0$)([1-9]\d*|0)(\.\d{2})?$/,message:'请输入正确的金额！', trigger: ['change', 'blur']},
					],
					isUseBusinessCard: [{ required: true, message: '请选择是否使用商务卡!', trigger: 'change' }],
					applyExplain: [{ required: true, message: '请输入报销说明!', trigger: 'blur' }],
					settleType:[{ required: true, message: '请选择结算方式!', trigger: 'change' }],
					accountName:[{ required: true, message: '请输入收款户名!', trigger: 'blur' }],
					transferType:[{ required: true, message: '请选择转账类型!', trigger: 'change' }],
					relBillId:[
							{ required: true, message: '请选择关联的单据!', trigger: 'change'},
					],
					relBillType:[
							{ required: false, message: '请选择冲账类型!', trigger: 'change'},
					],
					bankName:[{ required: true, message: '请输入收款方开户行!', trigger: 'blur' }],
					cnapsCode:[{ required: true, message: '请输入开户行联行号!', trigger: 'blur' }],
					accountNo:[{ required: true, message: '请输入收款方银行账户!', trigger: 'blur' }],
					postscript:[{ required: true, message: '请输入打款附言!', trigger: 'blur' }]
				}
			}
		},
		onLoad({id}) {
			this.initDictConfig()
			this.id=id
			
		},
		created() {
			
		},
		mounted() {
			/* 根据id获取详情 */
			if(this.id){
				//  编辑需要从详情里面拿数据
				this.getQueryById()
			}else{
				this.getInitData()
			}
		},
		watch:{
			'model.isPay':{
			  handler(val) {
				  if(val=='0'){
					  // this.model.payAmount='0.00'
				  }
			  },
			  deep: true,
			}
		},
		methods: {
			//加载数据字典信息
			initDictConfig() {
				initDictOptions('erp_omc_project,project_name,id').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'projectId', res.result)
					}
				})
				initDictOptions('erp_finance_loan_bill,bill_no,id').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'relLoanBillId', res.result)
					}
				})
				initDictOptions('erp_finance_payment_slip,bill_no,id').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'relPayBillId', res.result)
					}
				})
				initDictOptions('erp_omc_contract_manager_final,htmc,id').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'relContractId', res.result)
					}
				})
				initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'teamManager', res.result)
					}
				})
				initDictOptions('erp_omc_project_task,category_name,id').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'taskCategory', res.result)
					}
				})
				initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'teamId', res.result)
					}
				})
				// initDictOptions('tdnd_type').then((res) => {
				// 	if (res.success) {
				// 		this.$set(this.dictOptions, 'teamYear', res.result)
				// 	}
				// })
				initDictOptions('sys_category,name,code').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'bigCategory', res.result)
					}
				})
				initDictOptions('sys_category,name,code').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'smallCategory', res.result)
					}
				})
				initDictOptions('cost_invoice_type').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'isSpecial', res.result)
					}
				})
				initDictOptions('yjgsnd').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'performanceAttributionYear', res.result)
					}
				})
			},
			collapseView3Init() {
			  setTimeout(() => {
				this.$refs.collapseView3.init()
			  }, 500)
			},
			addReverse() {
				this.index = null
				this.basicForm = {}
				this.showReverseModal = true
			},
			closeReverseModal() {
				this.basicForm = {}
				this.$refs.ReverseForm.reset()
				this.index = null
				this.showReverseModal = false
			},
			openReverseModal() {
				this.$refs.ReverseForm.basicForm = this.basicForm
			},
			handleEditReverseForm([item, index]) {
				// this.reSetAreaCode(item)
				this.basicForm = {
					...item
				}
				this.index = index
				this.showReverseModal = true
				// this.collapseView3Init()
			},
			handleRemoveReverseForm(item) {
				this.model.chargedInfoList = this.model.chargedInfoList.filter((i) => i !== item)
				// 计算总金额
				this.handelCharedAmount()
				// this.collapseView3Init()
			},
			handelCharedAmount(){
				let chargedAmount = 0
				this.model.chargedInfoList.forEach(item=>{
					chargedAmount+=Number(item.chargedAmount);
				})
				this.model.chargedAmount = chargedAmount.toFixed(2)
			},
			/**
			 * 报销新增点击确认
			 */
			handleReverseSubmit([data, index]) {
				this.showReverseModal = false
				if (typeof index === 'number') {
					this.$set(this.model.chargedInfoList, index, {
						...data
					})
				} else {
					this.model.chargedInfoList.push(data)
				}
				// this.$refs.ReverseForm.dataSource = this.model.chargedInfoList
				// 计算总金额
				this.handelCharedAmount()
				// this.collapseView3Init()
			},
			// 关联借款单 - 付款单
			handleApplicantChange(data){
				this.getRelBillData(data)
			},
			// 获取关联单号的金额等信息
			getRelBillData(data){
				let id=this.model.relBillId;
				if(this.model.relBillType=="1"){//借款单
					http.get("/api/erp/finance/borrow/erpFinanceLoanBill/queryById",{'id':id}).then((res) => {
						if (res.success) {
							let data=res.result;
							let loanAmount= Number(data.amount);//借款金额
							let onloanAmount=Number(data.repaymentAmount) + Number(data.travelReimbursementAmount) + Number(data.expenseReimbursementAmount);//已还金额
							let unloanAmount=loanAmount - onloanAmount;
							let amount=0;//报销金额
							if(this.model.feeCategory=="0"){
								// amount=this.model.salaryFeeInfo.amount;
								amount= Number(this.model.accumulateAmount);
							}else if(this.model.feeCategory=="1"){
								amount= Number(this.$refs.purchaseRef.purchaseyFeeInfo.amount);
							}else if(this.model.feeCategory=="2"){
								this.$refs.costRef.costList.forEach(item =>{
									amount+= Number(item.amount);
								})
							}
							let loadPayAmount=(amount - unloanAmount).toFixed(2);
							this.$set(this.model,'borrowLoanAmount',loanAmount);
							this.$set(this.model,'borrowOnloanAmount',onloanAmount);
							this.$set(this.model,'borrowUnloanAmount',unloanAmount);
							if(loadPayAmount>0){
								this.$set(this.model,'borrowPayAmount',loadPayAmount);
							}else{
								this.$set(this.model,'borrowPayAmount',0);
							}
						}
					})
				}else if(this.model.relBillType=="2"){//付款单
					http.get("/api/erp/finance/payment/erpFinancePaymentSlipFeeDetail/queryBillInfoByBillId",{'billId':id}).then((res) => {
						if (res.success) {
							let resResult=res.result.records[0];
							let payPayableAmount=resResult.currentPaidAmount;//应付金额
							let unChargedAmount=resResult.unChargedAmount;//未冲账金额
							let onChargedAmount=resResult.onChargedAmount;//冲账金额
							this.$set(this.model,'payUnChargedAmount',unChargedAmount);
							this.$set(this.model,'payOnChargedAmount',onChargedAmount);
							this.$set(this.model,'payPayableAmount',payPayableAmount);
						}
					})
				}else if(this.model.relBillType=="3"){//保证金
						let depositRemittanceAmount=data.remittanceAmount;//保证金总额
						let depositReturnAmount=data.returnAmount//归还总额
						let depositServiceCharge=data.serviceCharge;//服务费金额
						let depositInterestAmount=data.interestAmount;//利息金额
						let depositUnreturnAmount=data.unreturnAmount;//未还金额
						this.$set(this.model,'depositRemittanceAmount',depositRemittanceAmount);
						this.$set(this.model,'depositReturnAmount',depositReturnAmount);
						this.$set(this.model, 'depositUnreturnAmount', depositUnreturnAmount);
						this.$set(this.model,'depositServiceCharge',depositServiceCharge);
						this.$set(this.model,'depositInterestAmount',depositInterestAmount);
				}
			},
			// 获取详情
			async getQueryById(){
				let res = await queryByIdreimbursementBill({id:this.id})
				if(res.success){
					let { salaryFeeInfoList,purchaseyFeeInfo,dailyFeeInfoList}= await res.result
					
					// let keysList = Object.keys(res.result)
					// /* 根据key相同的数据进行映射、赋值 */
					// for (let modelKey in this.model) {
					// 	if(keysList.includes(modelKey)){
					// 		this.model[modelKey]=res.result[modelKey]
					// 	}
					// }
					this.model = Object.assign({}, res.result)
					if(res.result.feeCategory=='0'){
						// 选择了 工资福利类
						// let teamName = await filterMultiDictText(this.dictOptions['teamManager'], that.model.teamId + '')
						this.$nextTick(() => {
							salaryFeeInfoList.map(value => {
								value.bigCategoryName = filterMultiDictText(this.dictOptions['bigCategory'], value.bigCategory + '')
								value.smallCategoryName = filterMultiDictText(this.dictOptions['smallCategory'], value.smallCategory + '')
								value.isSpecial_dictText = filterMultiDictText(this.dictOptions['isSpecial'], value.isSpecial + '')
							})
							this.$refs.salaryRef.salaryFeeInfoList= salaryFeeInfoList
						})
						
					}else if(res.result.feeCategory=='1'){
						// 选择了 采购类
						this.$refs.purchaseRef.purchaseyFeeInfo= purchaseyFeeInfo
						this.$refs.purchaseRef.changeBigCategory('01', {id: purchaseyFeeInfo.bigCategory})
						this.$refs.purchaseRef.specialRules() // 发票类型验证规则
					}else if(res.result.feeCategory=='2'){
						// 选择了 费用类
						if(dailyFeeInfoList.length){
							this.model.isRelProject = dailyFeeInfoList[0].projectId?'1':'0'
						}
						this.timer = setTimeout(() => {
							clearTimeout(this.timer)
							this.timer = null
							this.$nextTick(() => {
								dailyFeeInfoList = this.getCostList(dailyFeeInfoList)
								this.$refs.costRef.costList = dailyFeeInfoList
								this.dailyFeeInfoList = dailyFeeInfoList // 获取费用类列表数据
							})
						}, 500)
					}
					if(res.result.relBillType&&(res.result.relBillType==1||res.result.relBillType==2)){
						http.get('/api/erp/finance/reimbursement/erpFinanceReimbursementChargedBillInfo/queryBillById',{ billId: res.result.id }).then(resspon => {
							if(resspon.success){
								let data = resspon.result;
								if (data.records != undefined) {
									data = data.records
								}
								this.model.chargedInfoList = data || []
							}
						})
					} else {
						this.model.chargedInfoList = []
					}
				}
			},
			getCostList (item = []) {
				if (item && item.length) {
					for (var i = 0; i < item.length; i++) {
						item[i].projectName = filterMultiDictText(this.dictOptions['projectId'], item[i].projectId + '')
						item[i].relContractId_dictText = filterMultiDictText(this.dictOptions['relContractId'], item[i].relContractId + '')
						item[i].taskCategory_dictText = filterMultiDictText(this.dictOptions['taskCategory'], item[i].taskCategory + '')
						item[i].bigCategoryName = filterMultiDictText(this.dictOptions['bigCategory'], item[i].bigCategory + '')
						item[i].smallCategoryName = filterMultiDictText(this.dictOptions['smallCategory'], item[i].smallCategory + '')
						item[i].isSpecial_dictText = filterMultiDictText(this.dictOptions['isSpecial'], item[i].isSpecial + '')
					}
				}
				return item
			},
			
			//判断是否付款
			isPay () {
				// this.model.payAmount='0.00'
				
				if (this.model.isPay == 0) {
					this.$set(this.model,'payAmount', '0.00');
					this.$set(this.rules, 'relBillType', [{ required: true, message: '请选择冲账类型!', trigger: 'change'}]);
					
				} else {
					this.radioSettleType(null);
					this.$set(this.rules, 'relBillType', [{ required: false, message: '请选择冲账类型!', trigger: 'change'}]);
				}
				this.$refs.form.clearValidate(['relBillType']);
				this.$nextTick(() => {
					this.$set(this.model,'settleType','');
					this.$set(this.model,'relBillType','');
				})
			},
			
			// 计算输入主表累计报销金额
			inputAmount(arg){
				if(arg==1){//工资福利
					// 计算累计报销金额
					if (this.$refs.salaryRef.salaryFeeInfoList && this.$refs.salaryRef.salaryFeeInfoList.length) {
						let salaryFeeInfoList= this.$refs.salaryRef.salaryFeeInfoList;
						let salaryFeeAmount=0;
						salaryFeeInfoList.forEach(item=>{
							salaryFeeAmount+= Number(item.amount);
						})
						this.$set(this.model,'accumulateAmount', Number(salaryFeeAmount).toFixed(2));
					}
					
					// // 计算剩余未付金额
					// if(this.model.borrowPayAmount!== undefined && this.model.borrowPayAmount!== null && this.model.borrowPayAmount!== ''){
					// 	// 报销金额 - 未还金额
					// 	// let borrowPayAmount=(this.model.salaryFeeInfo.amount-this.model.borrowUnloanAmount).toFixed(2);
					// 	let borrowPayAmount=(this.model.accumulateAmount - this.model.borrowUnloanAmount).toFixed(2);
					// 	if(borrowPayAmount>0){
					// 		this.$set(this.model,'borrowPayAmount',borrowPayAmount);
					// 	}else{
					// 		this.$set(this.model,'borrowPayAmount',0);
					// 	}
					// }
					// taxation 税费金额=0
					// if(this.model.salaryFeeInfo.amount && (this.model.salaryFeeInfo.taxation || this.model.salaryFeeInfo.taxation==0)){
					//   // 未税金额 = 报销金额 - 税费金额
					//   this.model.salaryFeeInfo.untaxedAmount=(this.model.salaryFeeInfo.amount-this.model.salaryFeeInfo.taxation).toFixed(2);
					// }
				}else if(arg==2){//采购
					// 累计报销金额
					if(this.$refs.purchaseRef.purchaseyFeeInfo.amount){
						this.$set(this.model,'accumulateAmount', Number(this.$refs.purchaseRef.purchaseyFeeInfo.amount).toFixed(2));
					}
					// if(this.model.borrowPayAmount !== undefined && this.model.borrowPayAmount !== null){
					// 	let borrowPayAmount=(this.$refs.purchaseRef.purchaseyFeeInfo.amount-this.model.borrowUnloanAmount).toFixed(2);
					// 	if(borrowPayAmount>0){
					// 		this.$set(this.model,'borrowPayAmount',borrowPayAmount);
					// 	}else{
					// 		this.$set(this.model,'borrowPayAmount',0);
					// 	}
					// }
					// if(this.$refs.purchaseRef.purchaseyFeeInfo.amount && (this.$refs.purchaseRef.purchaseyFeeInfo.taxation || this.$refs.purchaseRef.purchaseyFeeInfo.taxation==0)){
					// 		this.$refs.purchaseRef.purchaseyFeeInfo.untaxedAmount=(this.$refs.purchaseRef.purchaseyFeeInfo.amount-this.$refs.purchaseRef.purchaseyFeeInfo.taxation).toFixed(2);
					// }
				}else if(arg==3){//费用
					// 累计报销金额
					if (this.$refs.costRef.costList && this.$refs.costRef.costList.length) {
						let costList=this.$refs.costRef.costList;
						let costListAmount=0;
						costList.forEach(item=>{
							costListAmount+= Number(item.amount);
						})
						// 累计报销金额
						this.$set(this.model,'accumulateAmount',costListAmount.toFixed(2));
					}
					// if(this.model.borrowPayAmount !== undefined && this.model.borrowPayAmount !== null){
					// 	let dailyFeeInfoList=this.$refs.costRef.costList;
					// 	let amount=0;
					// 	dailyFeeInfoList.forEach(item=>{
					// 		amount+= Number(item.amount);
					// 	})
						
					// 	let borrowPayAmount=(amount-this.model.borrowUnloanAmount).toFixed(2);
					// 	if(borrowPayAmount>0){
					// 		this.$set(this.model,'borrowPayAmount',borrowPayAmount);
					// 	}else{
					// 		this.$set(this.model,'borrowPayAmount',0);
					// 	}
						
					// }
				}
			},
			
			// 采购类点击切换项目
			projectChange () {
				// 当有采购合同时会清空收款信息：accountName、bankName、accountNo
				this.$set(this.model,"accountName",'');
				this.$set(this.model,"bankName",'');
				this.$set(this.model,"cnapsCode",'');
				this.$set(this.model,"accountNo",'');
			},
			// 采购类点击采购合同
			getInformation (accountName) {
				if (this.model.settleType == '0' && this.model.transferType == '2'){
					this.$set(this.model,'accountName',accountName)
					
					let customerId = accountName
					this.getAccount(customerId)
				}
			},
			
			// 获取账户信息
			getAccount (customerId) {
				http.get('/api/erp/purchase/supplier/erpPurchaseSupplier/queryById', {id: customerId}).then((res) => {
					if (res.success) {
						//带出收款方开户行
						this.$set(this.model,'bankName',res.result.bankName)
						this.$set(this.model,'cnapsCode',res.result.cnapsCode)
						//带出收款方账户
						this.$set(this.model,'accountNo',res.result.bankAccountNo)
					}
				})
			},
			// 切换结算方式
			radioSettleType (ops) {
				if(ops=='0'){//转账
					//ERP迭代16.7 ： 当“结算方式”选择转账后，“转账类型”默认为供应商
					if (this.model.feeCategory == '1'){
						this.$set(this.model, 'transferType', '2');
						//非项目付款合同选择转账才能带出供方信息的公司名称
						
						if (!this.$refs.purchaseRef.purchaseyFeeInfo.projectId && this.$refs.purchaseRef.purchaseyFeeInfo.relContractId){
							http.get('/api/erp/purchase/contract/erpPurchaseContract/queryById', {id: this.$refs.purchaseRef.purchaseyFeeInfo.relContractId}).then((res) => {
								if (res.success) {
									//迭代16.7：“收款户名”从采购合同中带出供方信息的“公司名称”
									this.$set(this.model,'accountName',res.result.supplyCompanName)
									let customerId = res.result.supplyCompanName
									this.getAccount(customerId)
								}
							})
						}
					}else {
						this.$set(this.model, 'transferType', null);
					}
				}else if(ops=='2'){//冲账
					this.$set(this.model, 'transferType', null);
					this.$refs["form"].clearValidate('accountName');
					this.$refs["form"].clearValidate('bankName');
					this.$refs["form"].clearValidate('cnapsCode');
					this.$refs["form"].clearValidate('accountNo');
					this.$set(this.model, 'accountName', '');
					this.$set(this.model, 'bankName', '');
					this.$set(this.model, 'cnapsCode', '');
					this.$set(this.model, 'accountNo', '');
				}else{
					this.$set(this.model, 'transferType', null);
					this.$set(this.model, 'accountName', '');
					this.$set(this.model, 'bankName', '');
					this.$set(this.model, 'cnapsCode', '');
					this.$set(this.model, 'accountNo', '');
				}
			},
			
			// 选择冲账单据类型
			radioChange (data) {
				if(data==undefined) {
					this.$set(this.model, 'relBillType', '');
				}
				if(data){
					this.$set(this.model, 'relBillId', '');
					this.$set(this.model, 'borrowPayAmount', '');
					this.$set(this.model, 'borrowOnloanAmount', '');
					this.$set(this.model, 'borrowLoanAmount', '');
					this.$set(this.model, 'borrowUnloanAmount', '');
					this.$set(this.model, 'payApplicant', '');
					this.$set(this.model, 'payPayeeName', '');
					this.$set(this.model, 'payPayableAmount', '');
					this.$set(this.model, 'payUnChargedAmount', '');
					this.$set(this.model, 'payOnChargedAmount', '');
					this.$set(this.model, 'payPaidAmount', '');
					this.$set(this.model, 'payDeductionAmount', '');
					this.$set(this.model, 'depositRemittanceAmount', '');
					this.$set(this.model, 'depositReturnAmount', '');
					this.$set(this.model, 'depositUnreturnAmount', '');
					this.$set(this.model, 'depositServiceCharge', '');
					this.$set(this.model, 'depositInterestAmount', '');
					this.$set(this.model, 'chargedInfoList', []);
					this.handelCharedAmount()
				} else {
					this.$set(this.model, 'chargedAmount', '0.00');
					this.$set(this.model, 'chargedInfoList', []);
				}
			},
			
			//切换转账类型
			radioTransferType(data){
				if(data){
					if(this.model.accountName){
						this.$set(this.model, 'accountName', null);
						this.$set(this.model, 'bankName', '');
						this.$set(this.model, 'cnapsCode', '');
						this.$set(this.model, 'accountNo', '');
					}
				}
			},
			selectAccountName(val){
				let accountName=this.model.accountName
				http.get('/api/erp/files/employee/erpEmployeeFile/queryFileById',{id:accountName}).then(res => {
					if (res.success) {
						let result=res.result
						this.$set(this.model, 'bankName', result.bankName);
						this.$set(this.model, 'cnapsCode', result.cnapsCode);
						this.$set(this.model, 'accountNo', result.bankCard);
					}
				})
			},
			
			onJudge(){
				// 保存返回的监听，事先处理好
				uni.$on("supplierBack", res => {
					this.model.accountName = res.id
					this.selectCustomer(res)
					
					// 清除监听
					uni.$off('supplierBack');
				})
			
				uni.navigateTo({
					url:'/pages/common/selectSupplier/selectSupplierInput'+'?isProPayContract=1&isNoJudge=1'
				})
			},
			
			// 选择单位
			selectCustomer(data) {
				if(data){
					this.$set(this.model, 'bankName', data.bankName);
					this.$set(this.model, 'cnapsCode', data.cnapsCode);
					this.$set(this.model, 'accountNo', data.bankAccountNo);
				}
			},
			
			// 选择费用类是否关联项目
			changeCostRef (e) {
				this.$set(this.model, 'isRelProject', e)
				// this.model.isRelProject = e
			},
			
			// 获取费用类的列数据
			getDailyFeeInfoList (list) {
				this.dailyFeeInfoList = list
				if (list && list.length) {
					var projectId = list[0].projectId;
					if(this.model.relBillType=='3'){
						//如果项目存在
						if(projectId){
							this.$set(this.model, 'relBillType', '');
							this.$set(this.model, 'depositRemittanceAmount', '');
							this.$set(this.model, 'depositReturnAmount', '');
							this.$set(this.model, 'depositServiceCharge', '');
							this.$set(this.model, 'depositInterestAmount', '');
						}
					}
					
				} else {
					this.$set(this.model, 'relBillType', '')
				}
			},
			
			// 初始化赋值
			async getInitData(){
				
				this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');//赋值时间
				this.model.proposer = this.userInfo.empId;
				this.model.proposerDeptId = this.userInfo.deptId;
				
				/* 获取单号 */
				let res= await reimburseSlipBillNo()
				if(res.success){
					let data = res.result.records || res.result
					this.$set(this.model, 'billNo', data);
					this.$set(this.model, 'bpmBizTitle', this.userInfo.employee.name+'-'+data);
				}
				
			},
			// 公司变化
			async companyChange(data){
				if(data){
					if(this.model.relBillType){
						this.$set(this.model, 'relBillType',null);
						this.$set(this.model, 'relBillId', '');
						this.$set(this.model, 'borrowPayAmount', '');
						this.$set(this.model, 'borrowOnloanAmount', '');
						this.$set(this.model, 'borrowLoanAmount', '');
						this.$set(this.model, 'borrowUnloanAmount', '');
						this.$set(this.model, 'payApplicant', '');
						this.$set(this.model, 'payPayeeName', '');
						this.$set(this.model, 'payPayableAmount', '');
						this.$set(this.model, 'payUnChargedAmount', '');
						this.$set(this.model, 'payOnChargedAmount', '');
						this.$set(this.model, 'payPaidAmount', '');
						this.$set(this.model, 'payDeductionAmount', '');
						this.$set(this.model, 'depositRemittanceAmount', '');
						this.$set(this.model, 'depositReturnAmount', '');
						this.$set(this.model, 'depositUnreturnAmount', '');
						this.$set(this.model, 'depositServiceCharge', '');
						this.$set(this.model, 'depositInterestAmount', '');
					}
					//采购类
					if(this.model.feeCategory=='0'){
						// this.$set(this.model,'salaryFeeInfoList',[]);
						this.$refs.salaryRef.salaryFeeInfoList=[]
						this.$set(this.model,"accumulateAmount",0);
					}else if(this.model.feeCategory=='1'){
						// this.$set(this.model,'purchaseyFeeInfo',{});
						this.$refs.purchaseRef.toRest() // 清空采购类数据
						this.$set(this.model,"accumulateAmount",0);
					}else if(this.model.feeCategory=='2'){
						// this.$set(this.model,'dailyFeeInfoList',[]);
						this.$refs.costRef.costList = [] // 清空费用类
						this.$set(this.model,"accumulateAmount",0);
					}
				}
			},
			// 团队变化
			handleTeamChange(item) {
				this.$set(this.model,'teamYear',item.tdnd)
			  this.model.teamId=item.id
				// 采购类
				if(this.model.feeCategory=='1'){
					if(this.$refs.purchaseRef.purchaseyFeeInfo.relContractId){
						// this.model.purchaseyFeeInfo={};
						this.$refs.purchaseRef.toRest() // 清空采购类数据
					}
					//费用类
				}else if(this.model.feeCategory=='2'){
					if(this.$refs.costRef.costList){
							// this.model.dailyFeeInfoList=[];
							this.$refs.costRef.costList = []
					}
				}
				//清空冲账单据信息
				this.companyChange("1");
			},
			/**
			 * 修改值时，检查是否需要弹出对话框确认修改
			 * 取消 modal 的时候，需要将值还原
			 * @param {String} key BasicForm 中的key值
			 * @param {Function} fn 回调函数
			 * @param {any} data 回调函数参数
			 */
			checkSwitch(key, fn, data) {
			  this.$nextTick(() => {
			    if (this.isReset) return
			    const firstChar = key[0].toUpperCase()
			    key = firstChar + key.slice(1)
				const oldData = this[`backUp${key}`]
			    if (oldData && oldData !== this.model[key]) {
			      this.confirmModal = true
			      this.resetKey = `backUp${key}`
			    } else {
			      fn && fn(data)
			    }
				//切换团队清空数据
				// this.$set(this.model, 'itemList',[]);
				// this.$set(this.model,"payAmount",'');
				// this.$set(this.model, 'payeeBankName', null);
				// this.$set(this.model, 'payeeAccountNo', null);
				// this.$set(this.model,'payeeName',null);
				
			  })
			},
			// 费用类别切换
			feeCategoryChange(type){
				this.$refs.salaryRef.salaryFeeInfoList=[]
				this.model.feeCategory=type
				
				this.$refs.costRef.costList=[]
				
				this.$set(this.model,'settleType',null)
				this.$set(this.model,'transferType',null)
				this.$set(this.model,'bankName','') // 收款方开户行
				this.$set(this.model,'cnapsCode','') // 收款方开户行
				this.$set(this.model,'accountNo','') // 收款方银行账户
				
				this.$set(this.model,'accumulateAmount',0);
				this.$set(this.model,'salaryFeeInfo',{});
				// this.$set(this.model,'salaryFeeInfoList',[]);
				// this.$set(this.model,'purchaseyFeeInfo',{});
				this.$refs.purchaseRef.toRest() // 清空采购类数据
				// this.$set(this.model,'dailyFeeInfoList',[]);
				this.$set(this.model,'isRelProject',"1");
				// this.$set(this.model.purchaseyFeeInfo,'taxation',0);
				this.$refs.purchaseRef.purchaseyFeeInfo.taxation = 0
				this.$set(this.model.salaryFeeInfo,'taxation',0);
				
				this.$set(this.model, 'isRelProject', '1') // 修改费用类是否关联项目值
				// 当冲账单据类型为保证金申请单
				if(this.model.relBillType=='3'){
					this.$set(this.model, 'relBillType','');
					this.$set(this.model, 'relBillId', '');
					this.$set(this.model, 'depositRemittanceAmount', '');
					this.$set(this.model, 'depositReturnAmount', '');
					this.$set(this.model, 'depositUnreturnAmount', '');
					this.$set(this.model, 'depositServiceCharge', '');
					this.$set(this.model, 'depositInterestAmount', '');
				}
				this.handelCharedAmount()
			},
			
			// 获取标题时间
			getCreateTime() {
				let createTime = this.model.createTime;
				let date = createTime.substring(0,10)
				return date.substring(0,4) +'年'+ date.substring(5,7)+'月' + date.substring(8,10)+'日';
			},
			// 获取标题名称类型
			getTeamFeeCategoryTitle(){
				let feeCategory = ''
				switch (this.model.feeCategory) {
					case '0': feeCategory = '工资福利类';break;
					case '1': feeCategory = '采购类';break;
					case '2': feeCategory = '费用类';break;
				}
				return feeCategory;
			},
			
			//判断付款金额是否大于支付金额
			handleAmount(){
				// let model=this.model;
				// let borrowPayAmount= Number(model.borrowPayAmount)
				// if((borrowPayAmount || borrowPayAmount==0 ) && this.model.relBillType=="1"){//支付金额
				// 	if(borrowPayAmount< Number(model.payAmount)){
				// 		return true;
				// 	}
				// }
				// return false;
				let model=this.model;
				let accumulateAmount=model.accumulateAmount
				let chargedAmount=model.chargedAmount
				if(parseFloat(accumulateAmount)<parseFloat(chargedAmount)){
					return true;
				}
				return false;
			},
			//支付金额数据判断
			handlePayAmount(){
				let model=this.model;
				let feeCategory=model.feeCategory
				let payAmount= Number(model.payAmount)
				if(feeCategory=="0"){//工资福利
						// if(payAmount>model.salaryFeeInfo.amount){
							if(payAmount> Number(model.accumulateAmount)){
							return true;
						}
				}else if(feeCategory=="1"){//采购
						if(payAmount> Number(this.$refs.purchaseRef.purchaseyFeeInfo.amount)){
							return true;
						}
				}else if(feeCategory=="2"){//费用类
						let data=this.$refs.costRef.costList;
						let amount=0;
						data.forEach(item=>{
							amount+=Number(item.amount);
						})
						amount=amount.toFixed(2);
						if(payAmount>amount){
							return true;
						}
				}
				return false;
			},
			//支付金额数据判断是否大于报销后的冲账剩余金额
			handlePayAndChargedAmount(){
				let model=this.model;
				let feeCategory=model.feeCategory
				let payAmount=model.payAmount
				let accumulateAmount=model.accumulateAmount
				let chargedAmount=model.chargedAmount
				let unChargedAmount=(accumulateAmount-chargedAmount).toFixed(2)
				if(feeCategory=="0"){//工资福利
						// if(payAmount>model.salaryFeeInfo.amount){
							if(parseFloat(payAmount)>parseFloat(unChargedAmount)){
							return true;
						}
				}else if(feeCategory=="1"){//采购
						if(parseFloat(payAmount)>parseFloat(unChargedAmount)){
							return true;
						}
				}else if(feeCategory=="2"){//费用类
						if(parseFloat(payAmount)>parseFloat(unChargedAmount)){
							return true;
						}
				}
				return false;
			},
			//判断报销金额是否大于冲账金额
			handleChargedAmount(){
				let model=this.model;
				//冲账
				if(model.settleType=='2'){
					if(model.relBillType=='2'){
						let feeCategory=model.feeCategory
						let payAmount=model.payPaidAmount
						if(feeCategory=="0"){//工资福利
								// if(payAmount!=model.salaryFeeInfo.amount){
								if(payAmount!=model.accumulateAmount){
									return true;
								}
						}else if(feeCategory=="1"){//采购
								if(payAmount!=this.$refs.purchaseRef.purchaseyFeeInfo.amount){
									return true;
								}
						}else if(feeCategory=="2"){//费用类
								let data=this.$refs.costRef.costList;
								let amount=0;
								data.forEach(item=>{
									amount+=item.amount;
								})
								if(payAmount!=amount){
									return true;
								}
						}
					}
				}
				return false;
			},
			//判断报销金额是否大于保证金服务费金额
			handleDepositChargedAmount(){
				let model=this.model;
				//冲账
				if(model.relBillType=='3'){
					let feeCategory=model.feeCategory
					let payAmount=model.depositServiceCharge
					if(feeCategory=="0"){//工资福利
							// if(payAmount!=model.salaryFeeInfo.amount){
							if(payAmount!=model.accumulateAmount){
								return true;
							}
					}else if(feeCategory=="1"){//采购
							if(payAmount!=this.$refs.purchaseRef.purchaseyFeeInfo.amount){
								return true;
							}
					}else if(feeCategory=="2"){//费用类
							let data=this.$refs.costRef.costList;
							let amount=0;
							data.forEach(item=>{
								amount+=item.amount;
							})
							if(payAmount!=amount){
								return true;
							}
					}
				}
				return false;
			},
			//判断是否填写报销信息
			// handleDataIsExist(){
			// 	const that = this;
			// 	let model=this.model;
			// 	let feeCategory=model.feeCategory
			// 	if(feeCategory=='0'){
			// 		if(this.model.salaryFeeInfoList.length==0){
			// 			that.$message.warning('请填写工资福利类报销信息');
			// 			that.confirmLoading = false;
			// 			that.$emit('unButtonDisable');
			// 			return true;
			// 		}
			// 	}else if(feeCategory=='2'){
			// 		if(this.$refs.costRef.costList.length==0){
			// 			that.$message.warning('请填写费用类报销信息');
			// 			that.confirmLoading = false;
			// 			that.$emit('unButtonDisable');
			// 			return true;
			// 		}
			// 	}
			// 	return false;
			// },
			
			validateForm() {
			  return this.$refs.form.validate().then(async () => {
					const that = this;
					let model=this.model;
					let feeCategory=model.feeCategory
					if(feeCategory=='0'){
						if(this.$refs.salaryRef.salaryFeeInfoList.length==0){
							this.$u.toast('请填写工资福利类报销信息！');
							return Promise.reject('请填写工资福利类报销信息！')
						}
					}else if(feeCategory=='2'){
						if(this.$refs.costRef.costList.length==0){
							this.$u.toast('请填写费用类报销信息！');
							return Promise.reject('请填写费用类报销信息！')
						}
					}
					if((this.model.relBillType=='1' || this.model.relBillType=='2') && this.model.chargedInfoList.length==0){
						this.$u.toast('请填写冲账信息!');
						return Promise.reject('请填写冲账信息!')
					}
					if(this.handleAmount()){
						this.$u.toast('本次冲账金额不能大于报销金额！');
						return Promise.reject('本次冲账金额不能大于报销金额！')
					}
					if(this.handlePayAmount()){
						this.$u.toast('本次付款金额不能大于报销金额！');
						return Promise.reject('本次付款金额不能大于报销金额！')
					}
					if(this.handlePayAndChargedAmount()){
						this.$u.toast('本次付款金额不能大于报销金额冲账后的剩余金额！');
						return Promise.reject('本次付款金额不能大于报销金额冲账后的剩余金额！')
					}
					return Promise.resolve()
				}).finally(async () => {
					if (this.model.feeCategory=='1') {
						return this.$refs.purchaseRef.onSubmit()
					}
			  })
			},
			// 保存处理
			async getSubmitRequest(type) {
				var that = this
				if (type == 1) {
					await this.validateForm()
				}
				let salaryFeeInfoList=null
				let purchaseyFeeInfo={
					"taxation": 0
				}
				let dailyFeeInfoList=null
				if(this.model.feeCategory=='0'){
					// 选择了 工资福利类
					salaryFeeInfoList=this.$refs.salaryRef.salaryFeeInfoList
					if (type == 1) {
						if(salaryFeeInfoList.length==0){
							this.$u.toast('请添加费用报销信息')
							return
						}
					}
					
				}else if(this.model.feeCategory=='1'){
					// 选择了 采购类
					purchaseyFeeInfo= this.$refs.purchaseRef.purchaseyFeeInfo
					
				}else if(this.model.feeCategory=='2'){
					// 选择了 费用类
					dailyFeeInfoList = this.$refs.costRef.costList
					if (type == 1) {
						if(dailyFeeInfoList.length==0){
							this.$u.toast('请添加费用报销信息')
							return
						}
					}
				}
				if (type == 1) {
					if(this.model.isPay=='1'&&!this.model.payAmount){
						this.$u.toast('请输入本次付款金额！')
						return
					}
				}
				let teamName = await filterMultiDictText(this.dictOptions['teamManager'], that.model.teamId + '')
				let createTime = await this.getCreateTime()
				let teamFeeCategory = await that.getTeamFeeCategoryTitle()
				that.model.bpmBizTitle = await (teamName? teamName+ ' - ':'') + that.userInfo?.employee?.name + ' - ' + createTime +  (that.model.accumulateAmount? ' - ' + that.model.accumulateAmount :'') + (teamFeeCategory? ' - ' + teamFeeCategory :'') //标题
				this.loading=true
				this.isSubmit = true
				let response = null
				const params= {
					...this.model,
					salaryFeeInfo:{taxation:0},
					salaryFeeInfoList,
					purchaseyFeeInfo,
					dailyFeeInfoList,
				}
				/* 判断是编辑提交还是新建 */
				if(this.id){
					response = await feeReimburseEdit(params)
				}else{
					response = await feeReimburseAdd(params)
					this.id = response.result
				}
				/* 是否发起流程 */
				if(type===1){
					let flowCode= 'onl_erp_finance_reimbursement_bill'
					let formUrl= "/erp/finance/reimbursement/modules/ErpFinanceReimbursementBillForm"
          let formUrlMobile="/pages/synergy/erpFinanceReimbursementBillList"
					let processId="1559825734534545409"
					let beanName="erpFinanceReimbursementBillServiceImpl"
					this.$store.dispatch('getUpdateStatus',this.model.billNo).then(rr=>{
						this.$refs.processConfig.showPopup = true
						this.$refs.processConfig.formUrl = formUrl
						this.$refs.processConfig.formUrlMobile = formUrlMobile
						this.$refs.processConfig.flowCode = flowCode
						this.$refs.processConfig.edit(this.id, processId,beanName)
						this.loading=false
					})
				}else{
					this.$refs.uToast.show({
						message: response.message,
						type: 'default',
						complete () {
							this.isSubmit = false
							if (getCurrentPages().length > 1) {
								uni.navigateBack()
							} else {
								uni.reLaunch({
									url: '/pages/home/home'
								})
							}
							
						}
					})
				}
				
			},
			// 提交流程成功
			onOk () {
				this.$refs.uToast.show({
					message: '提交成功',
					type: 'success',
					complete () {
						if (getCurrentPages().length > 1) {
							uni.navigateBack()
						} else {
							uni.reLaunch({
								url: '/pages/home/home'
							})
						}
						
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import url("@/assets/inputStyle.scss");

	.trip-form-data {
		margin: 6px 0;

		::v-deep {
			.u-form-item__body {
				padding-top: 2px;
				padding-bottom: 2px;
			}
		}
	}

	.checkbox-item {
		display: flex;
		align-items: center;
	}
</style>
